import QtQuick 1.1
import com.nokia.meego 1.0
import MeeGoSettings 1.0

PageStackWindow {
    id: appWindow

    initialPage: mainPage

    Page {
        id: mainPage
        orientationLock: PageOrientation.LockPortrait


        Label {
            id: enabled_lbl
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 30
            text: "Status"
        }
        Label {
            id: enabled_lbl_2
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: enabled_lbl.bottom
            anchors.topMargin: 5
            font.pixelSize: 18
            text: "You can also use <b>VolumeUp+VolumeDown</b>"
        }
        Button {
            id: status_btn
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: enabled_lbl_2.bottom
            anchors.topMargin: 5
            checkable: true
            checked: enabled.value
            text: {
                if(checked)
                    if(long_btn.checked)
                        return "Multimedia + Volume"
                    else return "Multimedia"
                else return "Volume"
            }
            onClicked: enabled.value = checked
        }

        Label {
            id: long_lbl
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: status_btn.bottom
            anchors.topMargin: 30
            text: "Use long press for multimedia"
        }
        Button {
            id: long_btn
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: long_lbl.bottom
            anchors.topMargin: 5
            checkable: true
            checked: longpress.value
            text: {
                if(checked) return "Long press"
                else return "Short press"
            }
            onClicked: longpress.value = checked
        }

        Label {
            id: lpd_lbl
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: long_btn.bottom
            anchors.topMargin: 30
            text: "Long press duration"
        }

        Slider {
             id: longpressduration_sld
             anchors.horizontalCenter: parent.horizontalCenter
             anchors.top: lpd_lbl.bottom
             anchors.topMargin: 5

             stepSize:100
             valueIndicatorVisible: true
             valueIndicatorText: value/1000 + " s"
             value: longpressduration.value
             minimumValue:100
             maximumValue:2000

             onPressedChanged: {
                 longpressduration.value = value
             }
         }

        Label {
            id: vu_lbl
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: longpressduration_sld.bottom
            anchors.topMargin: 30
            text: "VolumeUp action"
        }

        ButtonRow {
            id: vu_buttons

            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: vu_lbl.bottom
            anchors.topMargin: 5

            Button {
                id: vu_pp
                text: "Play/Pause"
                onClicked: {volumeup.value = "playpause"}
                checked: {return volumeup.value == "playpause"}
            }
            Button {
                id: vu_p
                text: "Previous"
                onClicked: {volumeup.value = "previous"}
                checked: {return volumeup.value != "playpause" && volumeup != "next"}
            }
            Button {
                id: vu_n
                text: "Next"
                onClicked: {volumeup.value = "next"}
                checked: {return volumeup.value == "next"}
            }
        }

        Label {
            id: vd_lbl
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: vu_buttons.bottom
            anchors.topMargin: 30
            text: "VolumeDown action"
        }

        ButtonRow {
            id: vd_buttons
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: vd_lbl.bottom
            anchors.topMargin: 5

            Button {
                id: vd_pp
                text: "Play/Pause"
                onClicked: {volumedown.value = "playpause"}
                checked: volumedown.value == "playpause"
            }
            Button {
                id: vd_p
                text: "Previous"
                onClicked: {volumedown.value = "previous"}
                checked: volumedown.value == "previous"
            }
            Button {
                id: vd_n
                text: "Next"
                onClicked: {volumedown.value = "next"}
                checked: volumedown.value != "playpause" && volumedown.value != "previous"
            }
        }
    }

    GConfItem {
       id: volumeup
       objectName: "volumeup"
       key: "/apps/mediakeys/volumeup"
       defaultValue: "previous"
    }

    GConfItem {
       id: volumedown
       objectName: "volumedown"
       key: "/apps/mediakeys/volumedown"
       defaultValue: "next"
    }

    GConfItem {
       id: enabled
       objectName: "enabled"
       key: "/apps/mediakeys/enabled"
       defaultValue: true
       onValueChanged: updateStatus()
    }

    GConfItem {
       id: longpress
       objectName: "longpress"
       key: "/apps/mediakeys/longpress"
       defaultValue: true
    }

    GConfItem {
       id: longpressduration
       objectName: "longpressduration"
       key: "/apps/mediakeys/longpressduration"
       defaultValue: 800
    }

    function updateStatus() {
        if(enabled.value == true) status_btn.checked = true
        else status_btn.checked = false
    }

}
